import Color from 'color'
import {useThemeStore} from '@/stores'

/**
 * * 颜色变亮
 * hsl(100, 50%, 10%) -> hsl(100, 50%, 50%)
 * @param color 颜色
 * @param concentration 0~1 浓度
 * @returns
 */
export function lighten(color: string, concentration: number) {
    return Color(color).lighten(concentration).toString()
}

/**
 * * hsla 转换
 * @param color 颜色
 * @param alpha 默认1
 * @returns
 */
export function alpha(color: string, alpha = 1) {
    return Color(color).alpha(alpha).toString()
}

export const setHtmlTheme = (themeName?: string) => {
    const e = window.document.documentElement
    if (themeName) {
        e.setAttribute('data-theme', themeName)
        return
    }
    const designStore = useThemeStore()
    e.setAttribute('data-theme', designStore.themeName)
}

export const getImageUrl = (path: string) => {
    return new URL(`../assets/${path}`, import.meta.url).href
}
